/*!
 * Copyright (C) 2020 - All Rights Reserved by
 * @author : ZhaoYanbo
 * @email  : zyb920@hotmail.com
 * @created: 2020-10-31
 * @version: 1.0.0.0
 *
 */

#include "arcitem.h"
#include <QPainter>
#include <QtDebug>

ArcItem::ArcItem(QObject *parent, QGraphicsItem *item) : QObject(parent), QGraphicsRectItem(item)
{
    this->setFlags(QGraphicsItem::ItemIsFocusable);
}

void ArcItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    painter->save();
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setRenderHint(QPainter::SmoothPixmapTransform);
    {
        painter->setPen(Qt::NoPen);
        //painter->drawRect(this->rect());
        if(hasFocus()) {
            painter->setBrush(mFocusColor);
        } else {
            painter->setBrush(mColor);
        }
        //double d = mR * (mIndex + 1) * 2;
        painter->drawPie(QRect(-mD/2,this->rect().y(),mD,mD),     (90-mAngle/2)*16, mAngle*16);
        //painter->drawPie(QRect(-d/4,this->rect().y() + mR,d/2,d/2), (90-mAngle/2)*16, mAngle*16);
    }
    painter->restore();
}

void ArcItem::setColor(int r, int g, int b, int a)
{
    mColor = QColor(r,g,b,a);
    mFocusColor = QColor(255-r,255-g,255-b,a);
}

void ArcItem::setSize(double w, double h)
{
    this->setRect(-w/2, -h/2, w, h);
}

void ArcItem::setInfo(double d, double angle)
{
    mD = d;
    mAngle = angle;
}
